<?php
/**
 *
 */
namespace Yz\modules\News;

class Model_Default
    extends \Yz_Model_ActiveRecord
{

    /** Model's constructor requires module
     *  @param Yz_Module_Interface $module
     */
    protected function init()
    {
        debug();
        parent::init();
        $uploadImage = $this->module->selectModel('uploadImage');
        $stream = $this->module->selectModel('stream');
        $d =& $this->__dict__;
        $d['id']     = new \Yz_Property_Id();
        $d['date']   = new \Yz_Property_Date();
        $d['title']  = new \Yz_Property_String();
        $d['text']   = new \Yz_Property_RichText();
        $d['image']  = new \Yz_Property_ForeignKey($uploadImage, array('fieldName' => 'imageId'));
        $d['stream'] = new \Yz_Property_ForeignKey($stream, array('fieldName' => 'streamId'));
    }

    /**
     *
     *  @param int $id
     *  @return Yz_Item_Interface
     *  @throws NotFound
     */
    public function fetchItemByTitle($title)
    {
        debug();
        $action = $this->selectAction('SelectByTitle');
        $values = $action
            ->setTitle($title)
            ->perform()
            ->fetch()
        ;
        return $this->assignItem($values);
    }


}
